﻿using DoNetDrive.Common.Extensions;
using DoNetDrive.Core.Packet;
using DotNetty.Buffers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _8280WEBSocket.Command.Json
{
    internal class JsonPacket : INPacket
    {
        public static Encoding JsonEncoding = Encoding.UTF8;

        private string JsonString;
        public JsonPacket(string jString)
        {
            JsonString = jString;
        }
        public string GetJson()
        {
            return JsonString;
        }

        public void Dispose()
        {
        }

        public IByteBuffer GetPacketData(IByteBufferAllocator Allocator)
        {
            var sJson = GetJson();
            var iCount = JsonEncoding.GetByteCount(sJson);
            var buf = Allocator.Buffer(iCount);
            buf.WriteString(sJson, JsonEncoding);
            return buf;
        }

        public void ReleaseDataBuf()
        {

        }
    }
}
